import request from '@/utils/request'

/**
 * 商品详情
 * @param
 */
export const getGoodsDetail = (id, typeId = '0') => {
  return request('/api/goods/detail', 'post', { id, check_goods_type: typeId })
}

/**
 * 商品列表
 * @param {*} check_goods_type 0-商品 1-积分
 * @param {*} is_up 推荐商品
 * @param {*} brand 品牌
 * @param {*} place 产地
 * @param {*} internal 外径
 * @param {*} external 内径
 * @param {*} thickness 厚度
 * @param {*} grade 等级
 * @param {*} cid 分类 父级
 * @param {*} idct_id 分类 子级id
 * @returns {}
 */
export const getGoodsScreenList = (param) => {
  return request('/api/goods/lists', 'get', param)
}

/**
 * 添加到购物车 []
 * @param {String} goods_id 商品id
 * @param {String} sku_id 型号
 * @param {String} num 数量
 * @returns
 */
export const addCart = (param) => {
  return request('/api/goods/cartAdd', 'post', { goods_info: [param] })
}

/**
 * 获取购物车列表
 * @returns
 */
export const findCart = () => {
  return request('/api/goods/cartLists', 'get')
}

/**
 * 删除购物车商品
 * @param {String} id 购物车ID
 * @returns
 */
export const deleteCart = (id) => {
	
  return request('/api/goods/cartDel', 'post', { id })
}

/**
 * 购物车选中操作
 * @param {String} is_checked 是否选中
 * @param {Strgin} id 购物车id
 * @returns
 */
// eslint-disable-next-line camelcase
export const checkCartGoods = (is_checked, id) => {
  return request('/api/goods/cartModInfo', 'get', { is_checked, id })
}

/**
 * 清空购物车
 * @returns
 */
export const clearCart = () => {
  return request('/api/goods/clearCart', 'get')
}

// 下单
export const payOrder = (data) => {
  return request('/api/order/confirm', 'post', data)
}

/**
 * 订单详情
 * @param {String} order_id 订单号
 * @returns
 */
export const orderDetail = (id) => {
  return request('/api/order/detail', 'get', { order_id: id })
}

/**
 * 领取优惠券
 * @param {*} id 优惠券id
 * @returns
 */
export const getReceive = (id) => {
  return request('/api/coupon/receive', 'get', { id })
}

/**
 * 获取优惠券
 * @returns
 */
export const getPreview = () => {
  return request('/api/order/preview', 'get')
}

/**
 * 收藏
 * @param {Array} goodsInfo 商品id
 * @param {String} isColl 1-收藏 0-取消收藏
 * @returns
 */
export const goodsColl = (goodsInfo, isColl) => {
  return request('/api/goods/coll', 'post', { goods_info: [...goodsInfo], is_coll: isColl })
}

/**
 * 支付订单
 * @param {*} pay_way pay_way 支付方式 money-钱包支付 wechat_native-微信扫码支付 wechat_mini-小程序支付 wechat_jsapi-公众号支付 wechat_h5-网页h5支付 wechat_app-微信APP支付 alipay_app-支付宝app支付 alipay_h5-支付宝网页支付
 * @param {String} order_no 订单号
 * @returns
 */
export const paymentOrder = (data) => {
  return request('/api/pay/info', 'post', data)
}

/**
 * 查询订单支付状态
 * @param {*} id 订单ID
 * @returns
 */
export const checkOrderPay = (id) => {
  return request('/api/pay/check_order_pay', 'get', { order_id: id })
}

/**
 * 售后详情
 * @param {*} id 订单 id
 * @returns
 */
 export const backInfo = (id) => {
  return request('/api/order/backInfo', 'get', { id })
}

/**
 * 申请售后
 * @param {*} data id-订单id content-申请内容 img-图片 reason-原因
 * @param {*} data back_kd 物流  back_kd_no 物流单号
 * @returns
 */
export const salesAfterCreate = (data) => {
  return request('/api/order/salesAfterCreate', 'post', data)
}

export default {
  getGoodsDetail,
  getGoodsScreenList,
  addCart,
  findCart,
  deleteCart,
  checkCartGoods,
  clearCart,
  payOrder,
  orderDetail,
  getReceive,
  getPreview,
  goodsColl,
  paymentOrder,
  checkOrderPay,
  backInfo,
  salesAfterCreate
}